Imports System.Data.SqlClient
Public Class cls_ptioga_

    Implements ICloneable

#Region "Variables ..."
    Private int_idptioga As Integer = 0
    Private dbl_diametronominalp As Double = 0
    Private dbl_diametronominalm As Double = 0
    Private dbl_odp As Double = 0
    Private dbl_odm As Double = 0
    Private str_ansi As String = ""
    Private str_asme As String = ""
    Private str_asmes As String = ""
    Private dbl_espesorp As Double = 0
    Private dbl_espesorm As Double = 0
    Private dbl_pesol As Double = 0
    Private dbl_pesok As Double = 0
    Private int_idregistro As Integer = 0

    Private obj_registro As cls_registro_ = Nothing
    Private col_Items As Collections.Generic.List(Of cls_ptioga_) = Nothing
#End Region

#Region "Propiedades ..."
    ReadOnly Property This
        Get
            Return Me
        End Get
    End Property
    ReadOnly Property ThisDescripcion As String
        Get
            Return Me.ToString
        End Get
    End Property
    ReadOnly Property pKey
        Get
            Return idptioga
        End Get
    End Property
    Property idptioga() As Integer
        Get
            idptioga = int_idptioga
        End Get
        Set(ByVal value As Integer)
            int_idptioga = value
        End Set
    End Property
    Property diametronominalp() As Double
        Get
            diametronominalp = dbl_diametronominalp
        End Get
        Set(ByVal value As Double)
            dbl_diametronominalp = value
        End Set
    End Property
    Property diametronominalm() As Double
        Get
            diametronominalm = dbl_diametronominalm
        End Get
        Set(ByVal value As Double)
            dbl_diametronominalm = value
        End Set
    End Property
    Property odp() As Double
        Get
            odp = dbl_odp
        End Get
        Set(ByVal value As Double)
            dbl_odp = value
        End Set
    End Property
    Property odm() As Double
        Get
            odm = dbl_odm
        End Get
        Set(ByVal value As Double)
            dbl_odm = value
        End Set
    End Property
    Property ansi() As String
        Get
            ansi = str_ansi
        End Get
        Set(ByVal value As String)
            str_ansi = value
        End Set
    End Property
    Property asme() As String
        Get
            asme = str_asme
        End Get
        Set(ByVal value As String)
            str_asme = value
        End Set
    End Property
    Property asmes() As String
        Get
            asmes = str_asmes
        End Get
        Set(ByVal value As String)
            str_asmes = value
        End Set
    End Property
    Property espesorp() As Double
        Get
            espesorp = dbl_espesorp
        End Get
        Set(ByVal value As Double)
            dbl_espesorp = value
        End Set
    End Property
    Property espesorm() As Double
        Get
            espesorm = dbl_espesorm
        End Get
        Set(ByVal value As Double)
            dbl_espesorm = value
        End Set
    End Property
    Property pesol() As Double
        Get
            pesol = dbl_pesol
        End Get
        Set(ByVal value As Double)
            dbl_pesol = value
        End Set
    End Property
    Property pesok() As Double
        Get
            pesok = dbl_pesok
        End Get
        Set(ByVal value As Double)
            dbl_pesok = value
        End Set
    End Property
    Property idregistro() As Integer
        Get
            idregistro = int_idregistro
        End Get
        Set(ByVal value As Integer)
            int_idregistro = value
        End Set
    End Property

    Property Items() As Collections.Generic.List(Of cls_ptioga_)
        Get
            Items = col_Items
        End Get
        Set(ByVal value As Collections.Generic.List(Of cls_ptioga_))
            col_Items = value
        End Set
    End Property
    Property registro() As cls_registro_
        Get
            If IsNothing(obj_registro) Then
                obj_registro = New cls_registro_
                If Not obj_registro.Buscar(idregistro) Then
                    obj_registro = Nothing
                End If
            End If
            registro = obj_registro
        End Get
        Set(ByVal value As cls_registro_)
            obj_registro = value
        End Set
    End Property
#End Region

    Private Sub CargarColeccion(ByVal obj_Reader As SqlDataReader)
        col_Items = New Collections.Generic.List(Of cls_ptioga_)
        While obj_Reader.Read()
            Dim Elemento As New cls_ptioga_
            Elemento.int_idptioga = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idptioga")))

            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("diametronominalp"))) = False Then
                Elemento.dbl_diametronominalp = (obj_Reader.GetValue(obj_Reader.GetOrdinal("diametronominalp")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("diametronominalm"))) = False Then
                Elemento.dbl_diametronominalm = (obj_Reader.GetValue(obj_Reader.GetOrdinal("diametronominalm")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("odp"))) = False Then
                Elemento.dbl_odp = (obj_Reader.GetValue(obj_Reader.GetOrdinal("odp")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("odm"))) = False Then
                Elemento.dbl_odm = (obj_Reader.GetValue(obj_Reader.GetOrdinal("odm")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("ansi"))) = False Then
                Elemento.str_ansi = (obj_Reader.GetValue(obj_Reader.GetOrdinal("ansi")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("asme"))) = False Then
                Elemento.str_asme = (obj_Reader.GetValue(obj_Reader.GetOrdinal("asme")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("asmes"))) = False Then
                Elemento.str_asmes = (obj_Reader.GetValue(obj_Reader.GetOrdinal("asmes")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("espesorp"))) = False Then
                Elemento.dbl_espesorp = (obj_Reader.GetValue(obj_Reader.GetOrdinal("espesorp")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("espesorm"))) = False Then
                Elemento.dbl_espesorm = (obj_Reader.GetValue(obj_Reader.GetOrdinal("espesorm")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("pesol"))) = False Then
                Elemento.dbl_pesol = (obj_Reader.GetValue(obj_Reader.GetOrdinal("pesol")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("pesok"))) = False Then
                Elemento.dbl_pesok = (obj_Reader.GetValue(obj_Reader.GetOrdinal("pesok")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idregistro"))) = False Then
                Elemento.int_idregistro = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idregistro")))
            End If
            col_Items.Add(Elemento)
        End While
    End Sub

    Private Sub CargarVariables(ByVal obj_Reader As SqlDataReader)
        obj_Reader.Read()
        int_idptioga = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idptioga")))

        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("diametronominalp"))) = False Then
            dbl_diametronominalp = (obj_Reader.GetValue(obj_Reader.GetOrdinal("diametronominalp")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("diametronominalm"))) = False Then
            dbl_diametronominalm = (obj_Reader.GetValue(obj_Reader.GetOrdinal("diametronominalm")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("odp"))) = False Then
            dbl_odp = (obj_Reader.GetValue(obj_Reader.GetOrdinal("odp")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("odm"))) = False Then
            dbl_odm = (obj_Reader.GetValue(obj_Reader.GetOrdinal("odm")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("ansi"))) = False Then
            str_ansi = (obj_Reader.GetValue(obj_Reader.GetOrdinal("ansi")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("asme"))) = False Then
            str_asme = (obj_Reader.GetValue(obj_Reader.GetOrdinal("asme")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("asmes"))) = False Then
            str_asmes = (obj_Reader.GetValue(obj_Reader.GetOrdinal("asmes")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("espesorp"))) = False Then
            dbl_espesorp = (obj_Reader.GetValue(obj_Reader.GetOrdinal("espesorp")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("espesorm"))) = False Then
            dbl_espesorm = (obj_Reader.GetValue(obj_Reader.GetOrdinal("espesorm")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("pesol"))) = False Then
            dbl_pesol = (obj_Reader.GetValue(obj_Reader.GetOrdinal("pesol")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("pesok"))) = False Then
            dbl_pesok = (obj_Reader.GetValue(obj_Reader.GetOrdinal("pesok")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idregistro"))) = False Then
            int_idregistro = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idregistro")))
        End If
    End Sub

    Public Sub Nuevo(Optional ByVal ObtenerID As Boolean = False)
        Dim obj_Conexion As New cls_Conexion
        Try
            'Creacion de registro----------------------------------------------------
            If IsNothing(obj_registro) Then
                registro = New cls_registro_
                registro.fechacreado = Now
                registro.idusuariocreado = UsuarioLOG.idusuario
                registro.fechamodificado = Now
                registro.idusuariomodificado = UsuarioLOG.idusuario
                registro.idregistroestado = 1
                registro.idusuarioregistroestado = UsuarioLOG.idusuario
                registro.Nuevo(True)
                idregistro = obj_registro.idregistro
            End If
            '------------------------------------------------------------------------
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "ptioga__Nuevo"
                .Parameters.Add("@diametronominalp", SqlDbType.decimal).Value = dbl_diametronominalp
                .Parameters.Add("@diametronominalm", SqlDbType.decimal).Value = dbl_diametronominalm
                .Parameters.Add("@odp", SqlDbType.decimal).Value = dbl_odp
                .Parameters.Add("@odm", SqlDbType.decimal).Value = dbl_odm
                .Parameters.Add("@ansi", SqlDbType.NVarChar).Value = str_ansi
                .Parameters.Add("@asme", SqlDbType.NVarChar).Value = str_asme
                .Parameters.Add("@asmes", SqlDbType.NVarChar).Value = str_asmes
                .Parameters.Add("@espesorp", SqlDbType.decimal).Value = dbl_espesorp
                .Parameters.Add("@espesorm", SqlDbType.decimal).Value = dbl_espesorm
                .Parameters.Add("@pesol", SqlDbType.decimal).Value = dbl_pesol
                .Parameters.Add("@pesok", SqlDbType.decimal).Value = dbl_pesok
                .Parameters.Add("@idregistro", SqlDbType.int).Value = int_idregistro
                .ExecuteNonQuery()
            End With
            If ObtenerID Then
                CargarUltimo()
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al Crear el registro de ptioga_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Sub Modificar()
        Dim obj_Conexion As New cls_Conexion
        Try
            'Modificacion de registro------------------------------------------------
            registro.fechamodificado = Now : registro.idusuariomodificado = UsuarioLOG.idusuario
            registro.Modificar()
            '------------------------------------------------------------------------
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "ptioga__Modificar"
                .Parameters.Add("@idptioga", SqlDbType.int).Value = int_idptioga
                .Parameters.Add("@diametronominalp", SqlDbType.decimal).Value = dbl_diametronominalp
                .Parameters.Add("@diametronominalm", SqlDbType.decimal).Value = dbl_diametronominalm
                .Parameters.Add("@odp", SqlDbType.decimal).Value = dbl_odp
                .Parameters.Add("@odm", SqlDbType.decimal).Value = dbl_odm
                .Parameters.Add("@ansi", SqlDbType.NVarChar).Value = str_ansi
                .Parameters.Add("@asme", SqlDbType.NVarChar).Value = str_asme
                .Parameters.Add("@asmes", SqlDbType.NVarChar).Value = str_asmes
                .Parameters.Add("@espesorp", SqlDbType.decimal).Value = dbl_espesorp
                .Parameters.Add("@espesorm", SqlDbType.decimal).Value = dbl_espesorm
                .Parameters.Add("@pesol", SqlDbType.decimal).Value = dbl_pesol
                .Parameters.Add("@pesok", SqlDbType.decimal).Value = dbl_pesok
                .Parameters.Add("@idregistro", SqlDbType.int).Value = int_idregistro
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al Modificar el registro de ptioga_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Sub Eliminar(ByVal idptioga As Integer)
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "ptioga__Eliminar"
                .Parameters.Add("@idptioga", SqlDbType.int).Value = idptioga
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al Eliminar el registro de ptioga_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Function Buscar(ByVal idptioga As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            Buscar = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "ptioga__Buscar"
                .Parameters.Add("@idptioga", SqlDbType.int).Value = idptioga
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
                Buscar = True
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al Buscar el registro de ptioga_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Sub CargarUltimo()
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "ptioga__CargarUltimo"
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al CargarUltimo registro de ptioga_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Sub

    Public Function CargarXdiametronominalpXschedule(ByVal prm_diametronominalp As Integer, ByVal prm_schedule As String) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarXdiametronominalpXschedule = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "ptioga__CargarXdiametronominalpXschedule"
                .Parameters.Add("@diametronominalp", SqlDbType.Decimal).Value = prm_diametronominalp
                .Parameters.Add("@schedule", SqlDbType.NVarChar).Value = prm_schedule
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarXdiametronominalpXschedule = True
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al CargarXdiametronominalpXschedule los registros de ptioga_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Function CargarXdiametronominalp(ByVal prm_diametronominalp As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarXdiametronominalp = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "ptioga__CargarXdiametronominalp"
                .Parameters.Add("@diametronominalp", SqlDbType.Decimal).Value = prm_diametronominalp
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarXdiametronominalp = True
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al CargarXdiametronominalp los registros de ptioga_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Function CargarTodos(Optional ByVal idregistroestado As Integer = 1) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarTodos = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "ptioga__CargarTodos"
                .Parameters.Add("@idregistroestado", SqlDbType.Int).Value = idregistroestado
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarTodos = True
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al CargarTodos los registros de ptioga_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim obj_ptioga_Clon As New cls_ptioga_
        obj_ptioga_Clon.int_idptioga = Me.int_idptioga
        obj_ptioga_Clon.dbl_diametronominalp = Me.dbl_diametronominalp
        obj_ptioga_Clon.dbl_diametronominalm = Me.dbl_diametronominalm
        obj_ptioga_Clon.dbl_odp = Me.dbl_odp
        obj_ptioga_Clon.dbl_odm = Me.dbl_odm
        obj_ptioga_Clon.dbl_espesorp = Me.dbl_espesorp
        obj_ptioga_Clon.dbl_espesorm = Me.dbl_espesorm
        obj_ptioga_Clon.dbl_pesol = Me.dbl_pesol
        obj_ptioga_Clon.dbl_pesok = Me.dbl_pesok
        obj_ptioga_Clon.int_idregistro = Me.int_idregistro
        obj_ptioga_Clon.col_Items = Me.col_Items
        Return obj_ptioga_Clon
    End Function

End Class
